'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    this.ctx.body = 'hi, egg';
  }

  async phoneList() {
    let { brand, rom, os, page } = this.ctx.query;
    console.log('page------', page)
    let data = [
      {
        id: '00000001',
        brand: '三星',
        price: '2999.00',
        ram: '4GB',
        rom: '64GB',
        os: 'Android',
        description: '三星 Galaxy S 轻奢版（SM-G8750）4GB+64GB 谜夜黑 移动联通电信4G手机',
        comment: '26万+',
        image: 'https://img12.360buyimg.com/n7/jfs/t21211/237/2502696176/280201/bc494a2b/5b599011Nd88a8c7d.jpg'
      },
      {
        id: '00000002',
        brand: '华为',
        price: '2399.00',
        ram: '4GB',
        rom: '64GB',
        os: 'Android',
        description: '荣耀10 GT游戏加速 AIS手持夜景 6GB+64GB 幻影蓝全网通 移动联通电信',
        comment: '46万+',
        image: 'https://img10.360buyimg.com/n7/jfs/t17773/222/1772357349/201925/627b888c/5ad8614bN7b9187f7.jpg'
      },
      {
        id: '00000003',
        brand: '小米',
        price: '2699.00',
        ram: '4GB',
        rom: '64GB',
        os: 'Android',
        description: '小米8 全面屏游戏智能手机 6GB+64GB 黑色 全网通4G 双卡双待 拍照手机',
        comment: '28万+',
        image: 'https://img10.360buyimg.com/n7/jfs/t20569/241/521943946/338336/409b289f/5b0fcb56N90ae22f0.jpg'
      },
      {
        id: '00000004',
        brand: '苹果',
        price: '4799.00',
        ram: '2GB',
        rom: '64GB',
        os: 'ios',
        description: 'Apple iPhone 8 64GB 红色特别版 移动联通电信4G手机',
        comment: '86万+',
        image: 'https://img14.360buyimg.com/n7/jfs/t19342/199/1516671468/71132/8e37293d/5acc524cN424bbaa0.jpg'
      },
      {
        id: '00000005',
        brand: '三星',
        price: '719.00',
        ram: '1GB',
        rom: '8GB',
        os: 'Android',
        description: '三星 Galaxy On5（G5500）移动联通4G手机 智能老人机手机',
        comment: '200+',
        image: 'https://img10.360buyimg.com/n7/jfs/t9385/233/1415397580/251022/3deb2824/59b8cb9bN0ce11eb8.jpg'
      },
      {
        id: '00000006',
        brand: 'oppo',
        price: '4999.00',
        ram: '8GB',
        rom: '128GB',
        os: 'Android',
        description: 'OPPO Find X曲面全景屏 波尔多红 8GB+128GB 全网通 移动联通电信全网通',
        comment: '31万+',
        image: 'https://img13.360buyimg.com/n7/jfs/t23167/95/285071867/94556/c98fa4f6/5b2b6212N106d8382.jpg'
      },
      {
        id: '00000007',
        brand: '小米',
        price: '2699.00',
        ram: '6GB',
        rom: '128GB',
        os: 'Android',
        description: '小米MIX2S 全面屏游戏手机 6GB+128GB 白色 全网通4G 陶瓷手机',
        comment: '28万+',
        image: 'https://img10.360buyimg.com/n7/jfs/t16915/296/1042950134/187306/da89b445/5ab9e638N96c296a0.jpg'
      },
      {
        id: '00000008',
        brand: '苹果',
        price: '6599.00',
        ram: '2GB',
        rom: '64GB',
        os: 'ios',
        description: 'Apple iPhone X (A1865) 64GB 银色 移动联通电信4G手机',
        comment: '79万+',
        image: 'https://img12.360buyimg.com/n7/jfs/t7297/154/3413903491/65679/45ae4902/59e42830N9da56c41.jpg'
      }
    ];
    if (page === '2') {
      data = []
      for (let i=0; i<10; i++) {
        data.push({
          id: '00000007',
          brand: '小米',
          price: '2699.00',
          ram: '6GB',
          rom: '128GB',
          os: 'Android',
          description: '小米MIX2S 全面屏游戏手机 6GB+128GB 白色 全网通4G 陶瓷手机',
          comment: '28万+',
          image: 'https://img10.360buyimg.com/n7/jfs/t16915/296/1042950134/187306/da89b445/5ab9e638N96c296a0.jpg'
        })
      }
    }
    if (page === '3') {
      data = []
      for (let i = 0; i < 10; i++) {
        data.push({
          id: '00000008',
          brand: '苹果',
          price: '6599.00',
          ram: '2GB',
          rom: '64GB',
          os: 'ios',
          description: 'Apple iPhone X (A1865) 64GB 银色 移动联通电信4G手机',
          comment: '79万+',
          image: 'https://img12.360buyimg.com/n7/jfs/t7297/154/3413903491/65679/45ae4902/59e42830N9da56c41.jpg'
        })
      }
    }
    this.ctx.body = data.filter((item) => {
      // console.log(item[type], key)
      return (!brand || item.brand === brand) && (!rom || item.rom === rom) && (!os || item.os === os);
    })
  }

  async banner() {
    this.ctx.body = [
      {
        id: '00000006',
        image: 'https://img.alicdn.com/imgextra/i1/901409638/TB2MS2mE29TBuNjy0FcXXbeiFXa-901409638.jpg'
      },
      {
        id: '00000003',
        image: 'https://img.alicdn.com/imgextra/i4/2616970884/O1CN011IOuZIzhy1Po7c3_!!2616970884.jpg'
      },
      {
        id: '00000008',
        image: 'https://img.alicdn.com/imgextra/i1/1714128138/TB2FP5JHFuWBuNjSszbXXcS7FXa-1714128138.jpg'
      }
    ];
  }

  async filterMenu() {
    const { userName, passWord } = this.ctx.request.body;
    this.ctx.body = {
      brand: ['华为', '苹果', '三星', '小米', 'oppo'],
      rom: ['8GB以下', '8GB', '64GB', '128GB'],
      os: ['Android', 'ios']
    };
  }

  async pay() {
    this.ctx.body = {
      retcode: 1,
      msg: '结算成功'
    }
  }
}

module.exports = HomeController;
